<template>
  <div class="cartControl">
    <!-- 动画滑进来 滑出来-->
    <transition
      enter-active-class="animated slideInRight"
      leave-active-class="animated slideOutRight"
    >
      <el-row class="reduce" v-show="food.count">
        <!-- 动画旋转进来 旋转出来 -->
        <transition
          enter-active-class="animated rotateIn"
          leave-active-class="animated rotateOut"
        >
          <el-col
            class="iconfont icon-jian"
            @click.native.stop.prevent="reduce"
            v-show="food.count"
          ></el-col>
        </transition>
      </el-row>
    </transition>

    <el-row class="num" v-show="food.count">{{ food.count }}</el-row>
    <el-row class="add">
      <el-col
        class="iconfont icon-jia"
        @click.native.stop.prevent="add($event)"
      ></el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  props: {
    food: {
      type: Object,
    },
  },
  data() {
    return {};
  },
  methods: {
    // 点击按钮，增加数量
    add(e) {
      this.food.count ? this.food.count++ : this.$set(this.food, "count", 1);
    },
    // 点击按钮，减少数量
    reduce() {
      this.food.count--;
    },
  },
  computed: {},
};
</script>

<style>
.cartControl {
  display: flex;
}
.cartControl .reduce,
.cartControl .add {
  line-height: 24px;
  font-size: 24px;
  color: rgb(0, 160, 220);
  transition: all 0.5s linear;
}
.cartControl .num {
  line-height: 24px;
  width: 24px;
  font-size: 10px;
  text-align: center;
  color: rgb(147, 153, 159);
}
</style>
